package com.annie.boots.config;

import com.annie.boots.interceptor.LoginInterceptor;
import com.annie.boots.interceptor.RedisUrlCountInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class AdminWebConfig implements WebMvcConfigurer {

    /**
     * Filter、Interceptor 几乎都有相同的功能
     * 1、Filter是Servlet定义的组件，好处就是脱离Sprig也能使用
     * 2、Iterceptor 是Spring定义的接口，可以使用Spring的自动装配等等
     */
    @Autowired
    RedisUrlCountInterceptor countInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/**")  //所有请求都被拦截包括静态资源
                .excludePathPatterns("/","/login","/css/**","/fonts/**","/images/**","/js/**","/lay/**","/lib/**"); //放行的请求
//        registry.addInterceptor(countInterceptor)
//                .addPathPatterns("/**")
//                .excludePathPatterns("/","/login","/css/**","/fonts/**","/images/**","/js/**");
    }
}
